import json
from channels.generic.websocket import WebsocketConsumer
message_connections = dict()
class DynamicMessageView(WebsocketConsumer):
    def connect(self):
        self.accept()

    def disconnect(self, close_code):
        message_connections[self.group].remove(self)
        print(self.group + "断开连接")
        print("当前组总连接数"+str(len(message_connections[self.group])))
    def receive(self, text_data):
        print(text_data)
        self.group =  json.loads(text_data)['group']
        if self.group not in message_connections:
            message_connections[self.group] = list()
        message_connections[self.group].append(self)
        print(self.group+"新增连接")
